package com.pcj.service.impl;

import com.pcj.mapper.UserMapper;
import com.pcj.pojo.User;
import com.pcj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @program: wechat
 * @author: 作者
 * @create: 2022-03-03 10:48
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(String id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public User selectByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    @Transactional
    @Override
    public User insert(User user) {
        user.setId(new Date().toString());
        userMapper.insert(user);
        return user;
    }

    @Override
    public User updateUserInfo(User user) {
        userMapper.updateByPrimaryKeySelective(user);
        User userResult = userMapper.selectByPrimaryKey(user.getId());
        return userResult;
    }
}
